{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "def day_of_year(year, month, day):\n",
    "    \"\"\"\n",
    "    计算给定日期是这一年的第几天\n",
    "    :param year: 年份\n",
    "    :param month: 月份（1-12）\n",
    "    :param day: 日期（1-31，根据月份而定）\n",
    "    :return: 给定日期是这一年的第几天\n",
    "    \"\"\"\n",
    "    # 创建datetime对象\n",
    "    date = datetime(year, month, day)\n",
    "    # 使用timetuple()方法获取日期的时间元组，然后取tm_yday属性\n",
    "    # tm_yday表示一年中的第几天（1-366，闰年有366天）\n",
    "    return date.timetuple().tm_yday\n",
    "\n",
    "# 示例：输入某年某月某日\n",
    "year = int(input(\"请输入年份: \"))\n",
    "month = int(input(\"请输入月份: \"))\n",
    "day = int(input(\"请输入日期: \"))\n",
    "\n",
    "# 调用函数并打印结果\n",
    "result = day_of_year(year, month, day)\n",
    "print(f\"{year}年{month}月{day}日是这一年的第{result}天。\")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
